<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    request.setAttribute("path", path);
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">
    <title>标题</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css"/>
    <script type="text/javascript" src="${pageContext.request.contextPath}/layui/layui.js"></script>

</head>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>驳回订单信息</legend>
</fieldset>

<%--头部栏--%>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container" >
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
    </div>
</script>
<%--入库信息表--%>
<table class="layui-table" id="test" lay-filter="test"></table>
<%--右侧操作栏--%>
<script type="text/html" id="barDemo">
    <a  class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit">查看详情</a>
    <a  class="layui-btn layui-btn-danger layui-btn-xs" lay-event="two">再次申请</a>
</script>

</body>
<script type="text/javascript">
    layui.use(['table','jquery','laydate','layer','form'], function(){
        var table = layui.table;
        var $=layui.jquery;
        var laydate=layui.laydate;
        var layer=layui.layer;
        var form=layui.form;

        $(function () {
            showReject();
            detailInfo();
        });

        function showReject(){
        table.render({
            elem: '#test'
            ,url:'${pageContext.request.contextPath}/reject/getAllReject'
            ,toolbar: '#toolbarDemo'
            ,title: '入库申请记录'
            ,totalRow: true
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'id', title:'ID', fixed: 'left', unresize: true, sort: true}
                ,{field:'audit_number', title:'申请单编号'}
                ,{field:'staffid', title:'申请人id'}
                ,{field:'staffname', title:'申请人名字'}
                ,{field:'bookcount', title:'总量(本)', width:100, sort: true}
                ,{field:'bookprice', title:'总价(元)', width:100, sort: true}
                ,{field:'createdate', title:'创建时间'}
                ,{field:'status', title:'状态', width:110,templet:function (d) {
                        if(d.status==0){
                            return "<button class='layui-btn layui-btn-xs layui-btn-normal'>待审核</button>";
                        }else if(d.status==1){
                            return "<button class='layui-btn layui-btn-xs layui-btn-danger'>审核通过</button>";
                        }else {
                            return "<button class='layui-btn layui-btn-xs layui-btn-danger'>被驳回</button>";
                        }
                    }}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo'}
            ]]
            ,page: true
            ,limit:5 //设置一页几条
            ,limits:[5,10,15] //放置可供
            ,text:{
                none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
            }
        });
        }



        function detailInfo(number){
            table.render({
                type:1,
                elem: '#detailInfo'
                ,url:'${pageContext.request.contextPath}/reject/showInfoReject?audit_number='+number
                ,title: '订单详情'
                ,cols: [[
                    // {type: 'checkbox', fixed: 'left'}
                    {field:'id', title:'ID',fixed: 'left',hide:true,unresize: true, sort: true}
                    ,{field:'audit_number', title:'采购编号'}
                    ,{field:'bookname', title:'书名'}
                    ,{field:'price', title:'进价'}
                    ,{field:'bookcount', title:'总量(本)',sort: true}
                    // ,{field:'count', title:'库存数量'}
                    ,{field:'publisher', title:'出版社'}
                    // ,{field:'disagree', title:'审核意见',edit:true}
                    // ,{fixed: 'right', title:'操作', toolbar: '#barDemo'}
                ]]
                ,page: true
                ,limit:5 //设置一页几条
                ,limits:[5,10,15] //放置可供
                ,text:{
                    none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
                }
            });
        }

        //头工具栏事件  申请采购表
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选');
                    break;

                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });


        //监听审核记录表的行工具事件
        table.on('tool(test)', function(obj){
            var data=obj.data;
            if(obj.event==='edit'){
                layer.open({
                    type: 1,
                    content: '<table class="layui-hide" id="detailInfo" lay-filter="detailInfo"></table>', //这里content是一个普通的String
                    success:function () {
                        detailInfo(data.audit_number);
                        //layer.closeAll();
                    }
                });
                //再次申请
            }else if(obj.event==='two'){
                var data=obj.data;
                //alert(data)
                /*var checkStatus = table.checkStatus(obj.config.id);
                var outDatas = checkStatus.data;*/
                $.ajax({
                    type:'post',
                    url:'${pageContext.request.contextPath}/reject/updateStatus',
                    data:JSON.stringify(data),
                    contentType:'application/json',
                    dataType: 'json',
                    success:function (datasu) {
                        if(data.code==1){
                           // layer.closeAll();

                            layer.msg(datasu.msg,{icon:1});
                            showReject();
                            //window.location.href='showReject.jsp';
                        }else {
                            layer.msg(datasu.msg,{icon:1})
                        }
                    }
                });

            }
        });

    });
</script>
</html>
